<?php
/**
 * @政策类
 * 1、政策类型
 * 2、政策list
 * 3、政策详情
 * 4、政策数量
 * @作者
 * 万全强（php）
 */

namespace app\controller;

use app\controller\HomeBase;
use think\facade\Db;

use app\model\PolicyTypeModel;
use app\model\PolicyModel;


class Policy extends HomeBase
{
	
	private $PolicyModel;
	private $PolicyTypeModel;
	
	public function __construct(){
		
		parent::__construct();
		$this->PolicyTypeModel=new PolicyTypeModel();
		$this->PolicyModel=new PolicyModel();
	}
	/**
	 * 政策类别列表
	 *
	 * @return void
	 */
	public function GetPolicyTypeList()
	{
		$param=request()->param();
		$res=$this->PolicyTypeModel->GetList();
		return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
	}
	/**
	 * 政策列表
	 *
	 * @return void
	 */
	public function GetPolicyList()
	{
		$where="  a.status=1  ";
		
		$field="a.id,a.policy_name,a.accept_time,a.type_id,a.industry_id,a.country_id,a.province_id,a.city_id,a.area_id";
		
		$condition=[];
		
		/***关键字*/
		$keywords=request()->param('keywords','','trim');
		if(!empty($keywords)){
			$condition['keywords']=$keywords;
		}
		/***行业*/
		$industry_id=request()->param('industry_id',0,'intval');
		if(!empty($industry_id)){
			$condition['industry_id']=$industry_id;
		}
		/***类型*/
		$type_id = request()->param('type_id', 0, 'intval');
		if (!empty($type_id)) {
			$condition['type_id']=$type_id;
		}
		/***云端产业链*/
		$chain_id=request()->param('chain_id',0,'intval');
		if(!empty($chain_id)){
			$condition['chain_id']=$chain_id;
		}
		/***地方产业链*/
		$yun_chain_id=request()->param('yun_chain_id',0,'intval');
		if(!empty($yun_chain_id)){
			$condition['yun_chain_id']=$yun_chain_id;
		}
		
		/***城市*/
		$city_id=request()->param('city_id',0,'intval');
		if(!empty($city_id)){
			$condition['city_id']=$city_id;
		}
		
		$listobj=$this->PolicyModel->GetList($field,$condition);
		
		
		return json(['status'=>1,'msg'=>'获取成功','data'=>$listobj]);
	}
	/**
	 * 政策详情
	 *
	 * @return void
	 */
	public function GetPolicyDetail()
	{
		$param=request()->param();
		$id=isset($param['id'])?intval($param['id']):0;
		$result=$this->PolicyModel->detail($id);
		
		return json(['status'=>1,'msg'=>'获取成功','data'=>$result]);
		
	}
	/***
	 * 政策数量统计
	 * @return Json
	 */
	public  function GetPolicyTotal(){
		
		$condition=[];
		if($this->user_id){
			$condition['user_id']=$this->user_id;
		}
		
		$keywords = request()->param('keywords', '', 'trim');
		$keywords=preg_replace("/\\d+/",'', trim($keywords));
		if($keywords){
			$condition['keywords']=$keywords;
		}
		//类型
		$type_id = request()->param('type_id', 0, 'intval');
		if (!empty($type_id)) {
			$condition['type_id']=$type_id;
		}
		//地方
		$chain_id = request()->param('chain_id', 0, 'intval');
		if (!empty($chain_id)) {
			$condition['chain_id']=$chain_id;
		}
		//云端
		$yun_chain_id = request()->param('yun_chain_id', 0, 'intval');
		if (!empty($yun_chain_id)) {
			$condition['yun_chain_id']=$yun_chain_id;
		}
		
		$city_id = request()->param('city_id', 0, 'intval');
		if (!empty($city_id)) {
			$condition['city_id']=$city_id;
		}
		
		$industry_id = request()->param('industry_id', 0, 'intval');
		if (!empty($industry_id)) {
			$condition['industry_id']=$industry_id;
		}
		
		$total=$this->PolicyModel->GetTotal($condition);
		return json(['status'=>1,'msg'=>'获取成功','data'=>$total]);
	}
	
}
